package com.example.blog.service.impl;

import com.example.blog.dao.ArticleDao;
import com.example.blog.model.Article;
import com.example.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleDao articleDao ;

    @Override
    public Page articleList(int start, int limit) {
        start = start < 0 ? 0 : start;
        Pageable pageable = PageRequest.of(start, limit,Sort.Direction.ASC,"id");
        Page<Article> page = articleDao.findAll(pageable);
        return  page ;

    }
}
